﻿@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Web
@inherits FluentComponentBase

@namespace Microsoft.FluentUI.AspNetCore.Components

<CascadingValue Value="this" IsFixed="true">
    <div class="fluent-toast" id="@Id" tabindex="0" >
        <FluentStack Orientation="Orientation.Horizontal" Width="100%" VerticalAlignment="VerticalAlignment.Center" HorizontalGap="8">
            @if (_parameters.Icon is not null)
            {
                var Icon = _parameters.Icon.Value;
                <FluentIcon Value="@Icon.Value" Style="min-width: 16px;" Width="16px" Color="@Icon.Color"/>
            }

            <div class="fluent-toast-title">@_parameters.Title</div>
            <div class="fluent-toast-action">
                @switch (_parameters.TopCTAType)
                {
                    case ToastTopCTAType.Dismiss:
                        <FluentIcon Value="@(new CoreIcons.Regular.Size24.Dismiss())"
                                    Width="12px"
                                    Title="Close"
                                    Color="@Color.FillInverse"
                                    OnClick="@Close" />
                        break;
                    case ToastTopCTAType.Timestamp:
                        <span class="fluent-toast-small timestamp ">@_parameters.Timestamp.ToString("HH:mm tt")</span>
                        break;
                    case ToastTopCTAType.Action:
                       <FluentAnchor title="@_parameters.TopAction"
                                      Href="#"  
                                      Style="font-size: 14px; font-weight:400;"
                                      Appearance="Appearance.Hypertext"
                                      @onfocusin="@PauseTimeout"
                                      @onfocusout="@ResumeTimeout"
                                      OnClick="HandleTopActionClick">
                            @_parameters.TopAction
                        </FluentAnchor>
                        break;
                }
            </div>
        </FluentStack>
        @if (Instance.ContentType is not null)
        {
            <DynamicComponent Type="@Instance.ContentType" Parameters="@Instance.GetParameterDictionary()" />
        }
        @if (_parameters.PrimaryAction is not null || _parameters.SecondaryAction is not null)
        {
            <div class="fluent-toast-actions">
                @if (_parameters.PrimaryAction is not null)
                {
                    <FluentAnchor title="@_parameters.SecondaryAction"
                                  Href="#"
                                  Style="font-size: 14px; font-weight:400;"
                                  Appearance="Appearance.Hypertext"
                                  @onfocusin="@PauseTimeout"
                                  @onfocusout="@ResumeTimeout"
                                  OnClick="HandlePrimaryActionClick">
                        @_parameters.PrimaryAction
                    </FluentAnchor>
                }
                @if (_parameters.SecondaryAction is not null)
                {
                    <FluentAnchor title="@_parameters.SecondaryAction"
                                  Href="#"        
                                  Style="font-size: 14px; font-weight:400;"
                                  Appearance="Appearance.Hypertext"
                                  @onfocusin="@PauseTimeout"
                                  @onfocusout="@ResumeTimeout"
                                  OnClick="HandleSecondaryActionClick">
                        @_parameters.SecondaryAction
                    </FluentAnchor>
                }
            </div>
        }
    </div>
</CascadingValue>
